package com.tongji.mapper;

import com.bean.Mess;
import com.bean.WmsTCrDetails;
import com.bean.WmsTCustomer;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

public interface TongjiMapper {

    //库存盘点
    //刚进库存盘点时的货主查询
    @Select("select * from wms_t_customer where custName=#{custName}")
    List<WmsTCustomer> getAllCustomers(@Param(value = "custName") String custName);
    //有货的仓库的盘点
    // 仓库：显示仓库中有东西的那些仓库信息：如果仓库中100个位置trayState全部都是0，仓库不能显示
    @Select("select storeName from wms_t_store where wms_t_store.storeID in " +
            "(select storeID from wms_t_site where wms_t_site.siteID in " +
            "(select siteID from wms_t_tray where wms_t_tray.trayState ='1'))")
    List<String> getAllCangKu();
    //开始盘点
    @Select("select wms_t_store.storeName,wms_t_customer.custName,wms_t_site.siteID,wms_t_tray.trayID,wms_t_bill_details.detailsGoodsName,wms_t_bill_details.detailsGoodsSpec,wms_t_bill_details.detailsGoodsNum,wms_t_cr_details.chkrptID from wms_t_customer " +
            "left join wms_t_bill on wms_t_customer.custID = wms_t_bill.customerID " +
            "left join wms_t_bill_details on wms_t_bill.billID = wms_t_bill_details.billID " +
            "left join wms_t_tray on wms_t_bill_details.trayID = wms_t_tray.trayID " +
            "left join wms_t_site on wms_t_tray.siteID = wms_t_site.siteID " +
            "left join wms_t_store on wms_t_site.storeID = wms_t_store.storeID " +
            "left join wms_t_cr_details on wms_t_cr_details.detailsID=wms_t_bill_details.detailsID " +
            "where wms_t_customer.custName = #{custName} and wms_t_store.storeName = #{storeName}")
    List<WmsTCustomer> getHaveSomething(@Param(value = "custName") String custName,@Param(value = "storeName") String storeName);
    //判断数据是否存在[存在则不重复插入]
    @Select("select * from wms_t_cr_details where chkrptID = #{chkrptId}")
    List<Map<Object, Object>> getWmsTCrDetails(WmsTCrDetails wmsTCrDetails);
    //插入数据
    @Insert("insert into wms_t_cr_details (detailsID,chkrptID,detailsGoodsName,detailsSpec,detailsEditTime,detailsIsDel) \n" +
            "values(#{detailsId},#{chkrptId},#{detailsGoodsName},#{detailsSpec},#{detailsEditTime},'0')")
    void insertWmsTCrDetails(WmsTCrDetails wmsTCrDetails);



    //货主查询
    //查询所有仓库
    @Select("select storeName from wms_t_store")
    List<String> getHuoZhuAllCangKu();
    //查询所有货主
    @Select("select * from wms_t_customer where custName like '%${custName}%'")
    List<WmsTCustomer> getAllCust(@Param("custName")String custName);
    //货主查询的开始盘点
    @Select("select WMS_T_STORE.storeName,WMS_T_CUSTOMER.custName,WMS_T_SITE.siteID,WMS_T_TRAY.trayID,WMS_T_BILL_DETAILS.detailsGoodsName,WMS_T_BILL_DETAILS.detailsGoodsSpec,WMS_T_BILL_DETAILS.detailsGoodsNum,WMS_T_CR_DETAILS.detailsInput from wms_t_customer " +
            "left join wms_t_bill on wms_t_customer.custID = wms_t_bill.customerID " +
            "left join wms_t_bill_details on wms_t_bill.billID = wms_t_bill_details.billID " +
            "left join wms_t_tray on wms_t_bill_details.trayID = wms_t_tray.trayID " +
            "left join wms_t_site on wms_t_tray.siteID = wms_t_site.siteID " +
            "left join wms_t_store on wms_t_site.storeID = wms_t_store.storeID " +
            "left join wms_t_cr_details on wms_t_cr_details.detailsID=wms_t_bill_details.detailsID " +
            "where wms_t_customer.custName = #{custName} and wms_t_customer.custTel = #{telephone}")
    List<WmsTCustomer> getOne(String telephone,String custName);



    //盘点查询历史
    @Select("select * from wms_t_cr_details where detailsID = #{detailsID}")
    List<WmsTCrDetails> getOneWmsTCrDetails(String detailsID);
    //根据客户ID模糊查询数据(盘点记录查询)
    @Select("select * from wms_t_customer where custID = #{custID}")
    List<WmsTCustomer> getAllCustByCustID(String custID);
    //开始查询
    @Select("select \n" +
            "wms_t_cr_details.chkrptID, wms_t_customer.custName,wms_t_cr_details.detailsEditTime,wms_t_customer.custNote,wms_t_bill_details.detailsEditTime as 'lasttime',wms_t_cr_details.detailsIsDel from wms_t_customer " +
            "left join wms_t_bill on wms_t_customer.custID = wms_t_bill.customerID \n" +
            "left join wms_t_bill_details on wms_t_bill.billID = wms_t_bill_details.billID\n" +
            "left join wms_t_cr_details on wms_t_bill_details.detailsID = wms_t_cr_details.detailsID " +
            "where wms_t_customer.custID = #{custID} or  wms_t_cr_details.detailsEditTime between #{date} and #{date2}")
    List<Mess> getAllWmsTCrDetails(String custID,String date, String date2);

}
